package 算法.LeetCode91.每日打卡题目;

import java.util.ArrayList;
import java.util.List;

public class day29 {
    public static void main(String[] args) {
        List<Integer> arrays = new ArrayList<>();
    }
    public static int mySqrt(int x) {
        if (x == 0)
            return x;
        int l = 1, h = 0;
        String num = String.valueOf(x);
        num = num.substring(0, num.length() / 2);
        if (num.length() > 0) {
            h = Integer.parseInt(num);
            h = Math.pow(h, 2) > x ? h : h * 10;
        } else
            h = x;
        while (h - l > 1) {
            int mid = (h + l) / 2;
            if (Math.pow(mid, 2) == x)
                return mid;
            else {
                if (Math.pow(mid, 2) > x)
                    h = mid+1;
                else
                    l = mid-1;
            }
        }
        return l;
    }
}
